﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace JXT.PrimaryKey.Batman.WcfService.Services.Extensions
{
    public static class ServiceExtensions
    {
        public static string GetClientIp(this OperationContext context)
        {
            var properties = context.IncomingMessageProperties;   //获取传进的消息属性   
            var endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            return endpoint.Address;
        }

        public static int GetClientPort(this OperationContext context)
        {
            var properties = context.IncomingMessageProperties;   //获取传进的消息属性   
            var endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            return endpoint.Port;
        }
    }
}
